/**
 * 导航栏
 */
$(function() {
	keypress();
	$.ajax({
		type : "get",
		url : getContextPath() + "/menufront/menuList",
		async : true,
		error : function() {
			alert("网络错误");
		},
		success : function(data) {
			var MenuTpl = $("#menuTpl").html();
			var html = juicer(MenuTpl, data);
			$("#nav").html(html);

			// 一级菜单
			// 鼠标滑过，自动展开
			$('#nav>li').mouseenter(function() {
				$(this).addClass('open');
				$('#nav>li.open>a').css({
					"background-color" : "white",
					"color" : "#0033CC"
				});
			});
			// 鼠标离开，自动关闭
			$('#nav>li').mouseleave(function() {
				$(this).removeClass('open');
				$('#nav>li>a').css({
					"background-color" : "white",
					"color" : "#000"
				});

			});
			// 二级菜单
			// 鼠标滑过
			$('.dropdown-menu>li').mouseenter(function() {
				$(this).addClass('open');
				$('.dropdown-menu li.open a').css({
					"background-color" : "white",
					"color" : "#0000CC"
				});
			});
			// 鼠标离开
			$('.dropdown-menu>li').mouseleave(function() {
				$(this).removeClass('open');
				$('.dropdown-menu li a').css({
					"background-color" : "white",
					"color" : "#000"
				});

			});
		}
	})

})
function keypress() {
	$('#search').bind(
			'keypress',
			function(event) {
				if (event.keyCode == "13") {
					window.location.href = getContextPath()
							+ '/fronthome/searchInfo?search='
							+ $('#search').val();
				}
			});
}
